{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# _*Experiment with the Shor's Algorithm in Aqua*_\n",
    "\n",
    "This notebook demonstrates how to experiment with the `Shor`'s algorithm in `Qiskit Aqua`.\n",
    "\n",
    "We first import all necessary modules."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit import BasicAer\n",
    "from qiskit.aqua import QuantumInstance\n",
    "from qiskit.aqua.algorithms import Shor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The [Shor's Factoring Algorithm](https://en.wikipedia.org/wiki/Shor's_algorithm) is explained in more detail in the corresponding notebook located in the directory `algorithms`. With Aqua, we can create a `Shor` instance by simply providing the target integer to be factored and run it, as follows."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The list of factors of 15 as computed by the Shor's algorithm is [3, 5].\n"
     ]
    }
   ],
   "source": [
    "N = 15\n",
    "shor = Shor(N)\n",
    "backend = BasicAer.get_backend('qasm_simulator')\n",
    "quantum_instance = QuantumInstance(backend, shots=1024)\n",
    "ret = shor.run(quantum_instance)\n",
    "print(\"The list of factors of {} as computed by the Shor's algorithm is {}.\".format(N, ret['factors'][0]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
